package com.sn.author.controller;

import com.sn.author.common.annotation.Advice;
import com.sn.author.common.annotation.IgnoreToken;
import com.sn.author.domain.BaseResult;
import com.sn.author.domain.dto.LoginDTO;
import com.sn.author.domain.vo.AuthorCodeVo;
import com.sn.author.domain.vo.LoginVo;
import com.sn.author.service.dao.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @Author xiaom
 * @Date 2020/9/15 20:20
 * @Version 1.0.0
 * @Description <>
 **/
@RestController
@RequestMapping(value = "/author")
@Api(tags = "登录管理")
public class LoginApi {

    private final LoginService loginService;

    public LoginApi(LoginService loginService) {
        this.loginService = loginService;
    }

    @PostMapping(value = "/login")
    @IgnoreToken
    @ApiOperation("账号登录")
    public BaseResult<LoginDTO> login(@RequestBody @Valid LoginVo loginVo){
        return BaseResult.success(loginService.login(loginVo));
    }

    @PostMapping(value = "/sendAuthCode")
    @ApiOperation("发送验证码")
    public BaseResult<Boolean> sendAuthCode(@RequestBody AuthorCodeVo authorCodeVo){
        return BaseResult.success(loginService.sendAuthCode(authorCodeVo.getKey()));
    }
}
